<template>
	<view class="selectStore">
		<navBar backColor="#fff" background="transparent"></navBar>
		<!-- store电话 -->
		<view class="storePhone">
			<image :src="`${baseImg}/static/adminShop/selectStore/bg.png`" mode=""></image>
			<view class="phoneBox">
				<image :src="`${baseImg}/static/adminShop/selectStore/topImg.png`" mode=""></image>
				<view class="phone">{{mobile}}</view>
				<view>请选择店铺</view>
			</view>
			<view class="whiteBox"></view>
		</view>
		
		<!-- 店铺列表 -->
		<view class="storeList">
			<view class="item" v-for="(item,index) in storeList" :key="index" @click="selectStore(item.is_choose,item.user_id)">
				<image :src="item.logo.path" mode=""></image>
				<view class="right omit-1">
					{{item.title}}
					<view class="toStore">
						进入店铺
						<i class="iconfont icon-jinru"></i>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import service_enter from '@/service/enter.js'
	export default{
		data(){
			return{
				baseImg:this.$static,
				storeList:[],
				mobile:''
			}
		},
		onLoad(options) {
			this.mobile = options.mobile?options.mobile:'';
			this.getStoreList()
		},
		methods:{
			// 获取多店列表
			getStoreList(){
				uni.showLoading({
					title:'加载中...'
				})
				service_enter.getStoreList().then(res=>{
					console.log(res,'多店列表')
					if(res.code==1){
						this.storeList = res.data?res.data:[];
					}
				})
				uni.hideLoading()
			},
			
			// 选择店铺进入
			async selectStore(is_choose,change_user_id){
				if(is_choose==1){
					// 邀请超级管家的分享跳转
					let to_id = uni.getStorageSync('to_id'); //超级管家邀请团队成员时的id
					let steward_id = uni.getStorageSync('to_steward_id'); //超级管家邀请团队成员时的团队id
					console.log(to_id,steward_id,'-----====')
					if(to_id){
						uni.reLaunch({
							url:`/pages_superHK/pages/team/bindSuperHK?to_id=${to_id}&steward_id=${steward_id}`
						})
						return
					}
					// uni.switchTab({
					// 	url:'/pages/mall/index/index'
					// })
					uni.reLaunch({
						url:'/pagesFour/home/home'
					})
				}else{
					uni.removeStorageSync('token')
					// this.$tim.logout();
					let params = {
						user_id:this.$store.state.index.userId,
						change_user_id
					}
					await service_enter.selectStore(params).then(async res=>{
						if(res.code==1){
							let data = res.data
							let token = data.token.access_token
							let role = data.role
							let userId = data.user_id
							let sid = data.sid
							let marketId = data.market_id
							let moduleType = data.type; //超级管家类型
							let moduleTeamId = data.steward_id; //超级管家团队id
							this.$store.commit('index/SET_token', token)
							this.$store.commit('index/SET_role', role)
							this.$store.commit('index/SET_sid', sid)
							this.$store.commit('index/SET_userId', userId)
							this.$store.commit('index/SET_tokenTime', Date.now())
							this.$store.commit('index/SET_marketId', marketId)
							this.$store.commit('index/SET_moduleType', moduleType)
							this.$store.commit('index/SET_moduleTeamId', moduleTeamId)
							// uni.switchTab({
							// 	url:'/pages/mall/index/index'
							// })
							
							// 邀请超级管家的分享跳转
							let to_id = uni.getStorageSync('to_id'); //超级管家邀请团队成员时的id
							let steward_id = uni.getStorageSync('to_steward_id'); //超级管家邀请团队成员时的团队id
							if(to_id){
								uni.reLaunch({
									url:`/pages_superHK/pages/team/bindSuperHK?to_id=${to_id}&steward_id=${steward_id}`
								})
								return
							}
							
							await this.getAllRoot()
							let router = this.$store.state.index.page?this.$store.state.index.page.ability:[]
							console.log(router,'、、、、、')
							if(router.findIndex(item=>item.route == 'adminIndex')!=-1){ //总后台
								uni.reLaunch({
									url:'/pages_admin/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'shopIndex')!=-1){ //商家
								uni.reLaunch({
									url:'/pagesFour/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'designerIndex')!=-1){ //设计师
								uni.reLaunch({
									url:'/pageTwo/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'builderIndex')!=-1){ //施工队
								uni.reLaunch({
									url:'/pagesOne/constr/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'decorationIndex')!=-1){ //装修公司
								uni.reLaunch({
									url:'/pages_decoration/home/home'
								})
							}else if(router.findIndex(item=>item.route == 'promoterIndex')!=-1){
								// if(uni.getUserProfile){
								// 	uni.getUserProfile({
								// 		desc:'Wexin',  // 这个参数是必须的
								// 		success:res=>{
								// 			console.log(res)
								// 			if(res.errMsg == 'getUserProfile:ok'){
								// 				uni.setStorageSync('userInfo',res.userInfo)
												uni.reLaunch({
													url:'/pagesOne/distri/index/index'
												})
								// 			}
								// 		},
								// 		fail:err=>{
								// 			console.log(err)
								// 		}
								// 	})
								// }
							}else{
								uni.reLaunch({
									url:'/pages/enter/index/index'
								})
							}
						}
					})
				}
				
			},
			// 所有权限
			async getAllRoot(){
				let params = {
					user_id:this.$store.state.index.userId,
					page:1,
					pagesize:10
				}
				await this.$api.allRoot(params).then(res=>{
					console.log(res,'所有权限')
					if(res.code==1){
						let page = res.data
						this.page = page
						this.$store.commit('index/SET_page', page)
					}
				})
			},
			
			
		}
	}
</script>

<style lang="less">
	page{
		height: 100%;
	}
	.selectStore{
		height: 100%;
		background-color: #fff;
		position: relative;
		.storePhone{
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 568rpx;
			image{
				width: 100%;
				height: 568rpx;
			}
			.phoneBox{
				position: absolute;
				top: 50%;
				left: 0;
				right: 0;
				bottom: 0;
				transform: translateY(-25%);
				display: flex;
				flex-direction: column;
				align-items: center;
				font: 400 36rpx/48rpx PingFangSC-Regular;
				color: #fff;
				image{
					width: 116rpx;
					height: 104rpx;
				}
				.phone{
					margin-top: 18rpx;
				}
			}
			.whiteBox{
				position: absolute;
				bottom: -2rpx;
				left: 0;
				width: 100%;
				height: 112rpx;
				background-color: #fff;
				border-radius: 60rpx 60rpx 0px 0px;
			}
		}
		.storeList{
			width: 100%;
			margin-top: 568rpx;
			position: absolute;
			top: 0;
			left: 0;
			background-color: #fff;			padding-bottom: constant(safe-area-inset-bottom);			padding-bottom: env(safe-area-inset-bottom);
			.item{
				width: 598rpx;
				height: 180rpx;
				margin: 0 auto 80rpx;
				background-color: #F8F6F3;
				display: flex;
				align-items: center;
				border-radius: 16rpx;
				padding: 30rpx 60rpx;
				box-shadow: 0px 4rpx 12rpx rgba(0, 0, 0, 0.1);
				image{
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					margin-right: 60rpx;
				}
				.right{
					font: 400 36rpx/82rpx PingFang SC;
					color: #1A1C20;
					.toStore{
						font: 400 24rpx/24rpx PingFang SC;
						color: #939393;
						display: flex;
						align-items: center;
						.iconfont{
							font-size: 22rpx;
						}
					}
				}
			}
		}
	}
</style>
